package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.pojo.Blog;
import com.itheima.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author xuchangshuo
 * @date 2020/8/5 16:29
 */

@RestController
@CrossOrigin
@RequestMapping("/content")
public class BlogController {


    @Autowired
    private BlogService blogService;


    //通过Uid获取博客内容
    @RequestMapping("/getBlogByUid")
    public Result getBlogByUid(@RequestParam String uid) {
        Blog blog = blogService.getBlogByUid(uid);
        return new Result("success", blog);
    }

    //通过Uid获取博客点赞数
    @RequestMapping("/getBlogPraiseCountByUid")
    public Result getBlogPraiseCountByUid(@RequestParam String uid) {
        //todo
        int count = blogService.getBlogPraiseCountByUid(uid);
        return new Result("success", count);

    }

    //根据BlogUid获取同类型的博客
    @RequestMapping("/getSameBlogByBlogUid")
    public Result getSameBlogByBlogUid(@RequestParam String blogUid) {
        String bolgType = blogService.getBlogTypeByBlogUid(blogUid);
        List<Blog> sameBlogList = blogService.getSameBlogByBlogUid(bolgType);
        return new Result("success", sameBlogList);
    }

    //根据标签获取相关的博客
    @RequestMapping("/getSameBlogByTagUid")
    public Result getSameBlogByTagUid(@RequestParam String tagUid) {
        List<Blog> blogList = blogService.getSameBlogByTagUid(tagUid);
        return new Result("success", blogList);
    }

    //通过Uid给博客点赞
    @RequestMapping("/praiseBlogByUid")
    public Result praiseBlogByUid(@RequestParam String uid) {
        blogService.praiseBlogByUid(uid);
        return new Result("success", "已点赞");
    }

}
